package com.nulldev.util.logging;

import com.nulldev.util.JVM.Arguments;

public class LoggerFactory {
	public static Logger getGenericLogger(final Class<?> cls) {
		return Logger.instance;
	}

	public static Logger getLogger(final Class<?> cls) {
		return new Logger(cls.getName());
	}

	public static Logger getLogger(final Class<?> cls, final LoggerLook look, final boolean displayClassName) {
		final Logger l = new Logger(cls.getName());
		l.setLook(look);
		l.NEW_LOOK_DISPLAY_CLASS_NAME.set(displayClassName);
		return l;
	}

	public static Logger getLog(final Class<?> cls) {
		return new Logger(cls.getName());
	}

	public static Logger getLogger() {
		final Logger l = new Logger(Thread.currentThread().getStackTrace()[2].getClassName());
		l.NEW_LOOK_DISPLAY_CLASS_NAME.set(true);
		return l;
	}

	public static Logger getLogger(final LoggerLook look, final boolean displayClassName) {
		final Logger l = new Logger(Thread.currentThread().getStackTrace()[2].getClassName());
		l.setLook(look);
		l.NEW_LOOK_DISPLAY_CLASS_NAME.set(displayClassName);
		return l;
	}

	public static Logger getLoggerName(final String className) {
		return new Logger(className);
	}

	public static Logger getLogger(final boolean noInfo) {
		final Logger out = getLoggerName(Thread.currentThread().getStackTrace()[2].getClassName());
		out.infoEnabled.set(!noInfo);
		return out;
	}

	public static Logger getLoggerD(final boolean debug) {
		final Logger out = getLoggerName(Thread.currentThread().getStackTrace()[2].getClassName());
		out.debugEnabled.set(debug);
		return out;
	}

	public static Logger getLoggerDT(final boolean debug) {
		final Logger out = getLoggerName(Thread.currentThread().getStackTrace()[2].getClassName());
		out.traceEnabled.set(debug);
		out.debugEnabled.set(out.traceEnabled.get());
		return out;
	}

	public static Logger getLoggerD(final boolean debug, final LoggerLook look, final boolean displayClassName) {
		final Logger out = getLoggerName(Thread.currentThread().getStackTrace()[2].getClassName());
		out.debugEnabled.set(debug);
		out.traceEnabled.set(Arguments.hasArgument("--Logger.traceAsDebug") && debug);
		out.setLook(look);
		out.NEW_LOOK_DISPLAY_CLASS_NAME.set(displayClassName);
		return out;
	}

	public static Logger getLoggerD(final boolean debug, final String name) {
		final Logger out = getLoggerName(name);
		out.debugEnabled.set(debug);
		return out;
	}

	public static Logger getLoggerD(final boolean debug, final boolean displayClassName) {
		final Logger out = getLoggerName(Thread.currentThread().getStackTrace()[2].getClassName());
		out.debugEnabled.set(debug);
		out.NEW_LOOK_DISPLAY_CLASS_NAME.set(displayClassName);
		return out;
	}

	public static Logger getLoggerD(final boolean debug, final String name, final boolean displayClassName) {
		final Logger out = getLoggerName(name);
		out.debugEnabled.set(debug);
		out.NEW_LOOK_DISPLAY_CLASS_NAME.set(displayClassName);
		return out;
	}

	public static Logger getLoggerD(final boolean debug, final String name, final LoggerLook look, final boolean displayClassName) {
		final Logger out = getLoggerName(name);
		out.debugEnabled.set(debug);
		out.setLook(look);
		out.NEW_LOOK_DISPLAY_CLASS_NAME.set(displayClassName);
		return out;
	}

	public static Logger getLoggerName(final String string, final LoggerLook look, final boolean displayClassName) {
		final Logger l = getLoggerName(string);
		l.NEW_LOOK_DISPLAY_CLASS_NAME.set(displayClassName);
		l.setLook(look);
		return l;
	}
}
